<?php

declare(strict_types=1);

namespace App\Admin\Controller\System\Logs;

use App\Admin\Annotation\Auth;
use App\Admin\Annotation\Permission;
use App\Admin\Service\System\SystemApiLogService;
use App\Admin\Service\System\SystemLoginLogService;
use App\Admin\Service\System\SystemOperLogService;
use App\Admin\Service\System\SystemQueueLogService;
use DI\Attribute\Inject;
use Newbie\Annotation\Attributes\Route\Controller;
use Newbie\Annotation\Attributes\Route\DeleteMapping;
use Newbie\Annotation\Attributes\Route\GetMapping;
use Newbie\Annotation\Attributes\Route\PutMapping;
use Newbie\NewbieController;
use support\Request;
use support\Response;

/**
 * 日志控制器
 * Class LogsController
 * @package App\system\Controller\Logs
 */
#[Controller(prefix: "system/logs"), Auth]
class LogsController extends NewbieController {
    /**
     * 登录日志服务
     */
    #[Inject]
    protected SystemLoginLogService $loginLogService;

    /**
     * 操作日志服务
     */
    #[Inject]
    protected SystemOperLogService $operLogService;

    /**
     * 接口日志服务
     */
    #[Inject]
    protected SystemApiLogService $apiLogService;

    /**
     * 队列日志服务
     */
    #[Inject]
    protected SystemQueueLogService $queueLogService;

    /**
     * 获取登录日志列表
     * @param Request $request
     * @return Response
     */
    #[GetMapping("getLoginLogPageList"), Permission("system:loginLog")]
    public function getLoginLogPageList (Request $request): Response {
        return $this->success($this->loginLogService->getPageList($request->all()));
    }

    /**
     * 获取操作日志列表
     * @param Request $request
     * @return Response
     */
    #[GetMapping("getOperLogPageList"), Permission("system:operLog")]
    public function getOperLogPageList (Request $request): Response {
        return $this->success($this->operLogService->getPageList($request->all()));
    }

    /**
     * 获取接口日志列表
     * @param Request $request
     * @return Response
     */
    #[GetMapping("getApiLogPageList"), Permission("system:apiLog")]
    public function getApiLogPageList (Request $request): Response {
        return $this->success($this->apiLogService->getPageList($request->all()));
    }

    /**
     * 获取队列日志列表
     * @param Request $request
     * @return Response
     */
    #[GetMapping("getQueueLogPageList"), Permission("system:queueLog")]
    public function getQueueLogPageList (Request $request): Response {
        return $this->success($this->queueLogService->getPageList($request->all()));
    }

    /**
     * 删除队列日志
     * @param String $ids
     * @return Response
     */
    #[DeleteMapping("deleteQueueLog/{ids}"), Permission("system:queueLog:delete")]
    public function deleteQueueLog (string $ids): Response {
        return $this->queueLogService->delete($ids) ? $this->success() : $this->error();
    }

    /**
     * 重新加入队列
     * @param String $ids
     * @return Response
     */
    #[PutMapping("updateQueueLog/{ids}"), Permission("system:queueLog:produceStatus")]
    public function updateQueueLog (string $ids): Response {
        return $this->queueLogService->updateProduceStatus($ids) ? $this->success() : $this->error();
    }

    /**
     * 删除操作日志
     * @param String $ids
     * @return Response
     */
    #[DeleteMapping("deleteOperLog/{ids}"), Permission("system:operLog:delete")]
    public function deleteOperLog (string $ids): Response {
        return $this->operLogService->delete($ids) ? $this->success() : $this->error();
    }

    /**
     * 删除登录日志
     * @param String $ids
     * @return Response
     */
    #[DeleteMapping("deleteLoginLog/{ids}"), Permission("system:loginLog:delete")]
    public function deleteLoginLog (string $ids): Response {
        return $this->loginLogService->delete($ids) ? $this->success() : $this->error();
    }

    /**
     * 删除API访问日志
     * @param String $ids
     * @return Response
     */
    #[DeleteMapping("deleteApiLog/{ids}"), Permission("system:apiLog:delete")]
    public function deleteApiLog (string $ids): Response {
        return $this->apiLogService->delete($ids) ? $this->success() : $this->error();
    }
}
